from fastapi import FastAPI
from dbops import insert, query

app = FastAPI()


@app.get("/")
def read_root():
    return {"Hello": "World"}


# @app.get("/hhh")
# def hhh_root():
#     return {"Hello": "hhh"}


@app.get("/items/{item_id}")
def read_item(item_id: str):
    value = query(item_id)
    print(value)
    value0 = value[0][0] if value else None
    return {"item_id": item_id, "value": value0}


@app.get('/items/{item_id}/{value}')
def set_item(item_id: str, value: str):
    insert(item_id, value)
    return {"item_id": item_id, "value": value}
